package com.zeh.hander;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice //异常处理注解
public class controllerExceptionHandler {
    @ExceptionHandler(Exception.class) //表明是异常处理方法
    public ModelAndView exceptionHandler(HttpServletRequest request,Exception e){
        //将记录的异常信息返回到error页面
        ModelAndView mv = new ModelAndView();
        mv.addObject("url",request.getRequestURL());
        mv.addObject("exception",e);
        mv.setViewName("error/error");
        return mv;
    }
}
